package com.bgi.uims.common.dao.impl;

import java.io.Serializable;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.bgi.uims.common.dao.ICommonDao;
import com.bgi.uims.common.dto.Common;
import com.bgi.uims.common.dto.PageVo;
import com.bgi.uims.common.pulgin.BaseDaoiBatis;

/**
 * 
 * ClassName: CommonDao <br/>
 * Function: TODO 通用DAO. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2014-10-20 下午02:07:32 <br/>
 *
 * @author fukun
 * @version 
 * @since JDK 1.7
 */
@Repository
public class CommonDao extends BaseDaoiBatis implements ICommonDao,Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//database execute delete
	public Integer delete(Common obj) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().delete(obj.getDeleteSql(), obj);
	}
	//database execute insert
	public Object insert(Common obj) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().insert(obj.getInsertSql(), obj);
	}
	//database execute query list
	public PageVo query(Common obj) {
		// TODO Auto-generated method stub
		PageVo pageVo=new PageVo();
		//如果有页码和最大行号则分页查询
		if(obj.getPageSize()!=null&&obj.getCurrPage()!=null)
		{
			long total=getObjectTotal(obj.getQuerySql(),obj);
			pageVo.setTotal(total);
			if(total>0)
			{
				//分页
				pageVo.setRows(getSqlMapClientTemplate().queryForList(obj.getQuerySql(),obj,obj.getCurrPage(),obj.getPageSize()));
			}
		}
		else
		{
			//不分页
			pageVo.setRows(getSqlMapClientTemplate().queryForList(obj.getQuerySql(),obj));
		}
		return pageVo;
	}
	//database execute query one
	public Object queryOne(Common obj) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().queryForObject(obj.getQueryOneSql(),obj);
	}
	//database execute update
	public Integer update(Common obj) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().update(obj.getUpdateSql(),obj);
	}
	   
	    /* (non-Javadoc)  
	     * @see com.bgi.uims.common.dao.ICommonDao#insertList(com.bgi.uims.common.dto.Common, java.util.Map)  
	     */   
	    
	@SuppressWarnings("rawtypes")
	public Object insertList(Common obj, Map map) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().insert(obj.getInsertListSql(), map);
	}
}
